<template>
  <div class="register-container">
    <div class="register-box">
      <h2>加入我们的零食王国！</h2>
      <form @submit.prevent="handleRegister">
        <div class="input-group">
          <label for="username">用户名：</label>
          <input type="text" id="username" v-model="username" required placeholder="创建您的用户名">
        </div>
        <div class="input-group">
          <label for="email">邮箱：</label>
          <input type="email" id="email" v-model="email" required placeholder="您的电子邮箱">
        </div>
        <div class="input-group">
          <label for="password">密码：</label>
          <input type="password" id="password" v-model="password" required placeholder="设置您的密码">
        </div>
        <div class="input-group">
          <label for="confirmPassword">确认密码：</label>
          <input type="password" id="confirmPassword" v-model="confirmPassword" required placeholder="再次输入密码">
        </div>
        <button type="submit" class="submit-btn">开启美味冒险</button>
      </form>
      <p class="login-link">已有账号？<router-link to="/login">立即登录</router-link></p>
    </div>
  </div>
</template>
<script>
import { ref } from 'vue';
import { useRouter } from 'vue-router';
export default {
  name: 'Register',
  setup() {
    const router = useRouter();
    const username = ref('');
    const email = ref('');
    const password = ref('');
    const confirmPassword = ref('');
    const handleRegister = async () => {
      if (password.value !== confirmPassword.value) {
        alert('两次输入的密码不一致');
        return;
      }
      // 这里应该调用您的注册 API
      // 例如：const response = await api.register(username.value, email.value, password.value);
      // 如果注册成功：
      alert('注册成功！欢迎加入我们的零食王国！');
      router.push('/login');
    };
    return {
      username,
      email,
      password,
      confirmPassword,
      handleRegister
    };
  }
};
</script>
<style scoped>
.register-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: #FFF3E0; /* 淡橙色背景 */
}
.register-box {
  background-color: white;
  padding: 30px;
  border-radius: 10px;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
  width: 300px;
}
h2 {
  color: #FF6F00; /* 深橙色 */
  text-align: center;
  margin-bottom: 20px;
}
.input-group {
  margin-bottom: 15px;
}
label {
  display: block;
  margin-bottom: 5px;
  color: #FF6F00;
}
input {
  width: 100%;
  padding: 10px;
  border: 1px solid #FFB74D; /* 浅橙色边框 */
  border-radius: 5px;
}
.submit-btn {
  width: 100%;
  padding: 10px;
  background-color: #FF6F00;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 16px;
  transition: background-color 0.3s;
}
.submit-btn:hover {
  background-color: #F57C00;
}
.login-link {
  text-align: center;
  margin-top: 15px;
}
a {
  color: #FF6F00;
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}
</style>
